# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__="kamillo"
__date__ ="$2009-11-07 12:58:07$"

from svq import *
import timeit

def readPoints(filename):
        input = []
        file = open(filename)
        lines = file.readlines()
        for line in lines:
            floated = []
            splitted = line.split(" ")
            for s in splitted:
                s = int(s)
                floated.append(s)
            input.append(floated)
        return input

def dosvq(times,beta,eta,cbvectors,od,do):
    points = readPoints("n_donut.txt")
    svq = SVQ(cbvectors,points,beta,eta)
    eta0 = eta
    m = svq.initCodeBook(False,[od,do])
    for i in range(times):
            m = svq.moveCodeBook(svq.calcF(svq.pickDataPoint()))
            svq.eta = eta0 * (times - i)/times
            #print svq.eta
            #self.svq.eta = eta0 / (i+1)
def dosvqopt(times,beta,eta,cbvectors,od,do):
    try:
        import psyco
        psyco.full()
    except:
        print "cant import psyco"
    dosvq(times,beta,eta,cbvectors,od,do)
if __name__ == "__main__":
    #try:
    #    import psyco
    #    psyco.full()
    #except:
    #    print "cant import psyco"
    print timeit.Timer('dosvq(5000,0.0002,0.5,100,200,400)','from __main__ import dosvq').timeit(1)
    print timeit.Timer('dosvqopt(5000,0.0002,0.5,100,200,400)','from __main__ import dosvqopt').timeit(1)
